//
//  WaitDispatchCell.m
//  BigJoy
//
//  Created by Rowling on 2017/7/11.
//  Copyright © 2017年 Rowling. All rights reserved.
//

#import "WaitDispatchCell.h"
#import "OrderSubCell.h"
#import "WuLIiuViewController.h"

@interface WaitDispatchCell()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UILabel *stautsLabel;
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *tableHeight;


@end

@implementation WaitDispatchCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.estimatedRowHeight = 110;
    self.tableView.scrollEnabled = NO;
    self.tableView.userInteractionEnabled = NO;
    self.tableHeight.constant = 110;
}

-(void)setCount:(NSInteger)count {
    _count = count;
    [self.tableView reloadData];
    self.tableHeight.constant = self.tableView.contentSize.height;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 110;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    OrderSubCell * cell = [OrderSubCell cellWithTalbelView:tableView];
    return cell;
}

-(void)setCellType:(CellType)cellType {
    _cellType = cellType;
    if (cellType == WaiteDispath) {
        //待发货
        [self.centerButton setTitle:@"申请退款" forState:UIControlStateNormal];
        [self.rightButton setTitle:@"提醒发货" forState:UIControlStateNormal];
        self.leftButton.hidden = YES;
        self.stautsLabel.text = @"待发货";
    }
    if (cellType == WaiteReceive) {
        //待收货
        [self.leftButton setTitle:@"退换货" forState:UIControlStateNormal];
        [self.centerButton setTitle:@"查看物流" forState:UIControlStateNormal];
        @weakify(self);
        [[self.centerButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            @strongify(self);
            WuLIiuViewController * vc = [WuLIiuViewController new];
            [[XMSuperHelper XMControllerOfView:self].navigationController pushViewController:vc animated:YES];
        }];
        [self.rightButton setTitle:@"确认收货" forState:UIControlStateNormal];
        self.leftButton.hidden = NO;
        self.stautsLabel.text = @"待收货";
    }
    if (cellType == WaitePay) {
        //待付款
        [self.centerButton setTitle:@"取消订单" forState:UIControlStateNormal];
        [self.rightButton setTitle:@"立即支付" forState:UIControlStateNormal];
        self.leftButton.hidden = YES;
        self.stautsLabel.text = @"待支付";
    }
}



+(instancetype)cellWithTalbelView:(UITableView *)table {
    WaitDispatchCell * cell = [table dequeueReusableCellWithIdentifier:@"WDCell"];
    if (cell == nil) {
        cell = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil].firstObject;
    }
    return cell;
}

@end
